package com.itheima.day13.thread.test14;

// 厨师类
public class Cooker extends Thread {
    @Override
    public void run() {
        int count = 0;
        while(true){
            // 上锁
            synchronized(Desk.obj){
                // 判断汉堡包是否做了完了
                if(Desk.count == 0)
                    break;
                // 判断桌子上是否有汉堡包
                if(Desk.boo){
                    // 有汉堡包
                    // 等待
                    try {
                        Desk.obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else{
                    // 无汉堡包
                    // 做汉堡包，叫醒吃货
                    System.out.println("厨师正在做汉堡包......");
                    try {
                        Thread.sleep(000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Desk.boo = true;
                    System.out.println("做完了,做了第" + (++count) + "个汉堡包\n");
                    Desk.obj.notify();
                }
            }
        }
    }
}
